import { Injectable } from '@angular/core';
// import { ModelLinkViewModel } from '../components/tree-directory/tree-directory.model';
import { CLOUDURL, FILEURL, MONITORURL, OLDTREEURL, PASSPORTURl, TREEURL, version } from '../config';
import { RequestClientService } from './request-client.service';
@Injectable()
export class BaseService {
  public constructor(private reqService: RequestClientService) {
  }
  public getHeaderTenantId() {
    return { TenantId: localStorage.getItem('TenantId') };
  }

  public async upImg(formData, tenantId?) {
    let header;
    if (tenantId) {
      header = { TenantId: tenantId };
    }
    let res = await this.reqService.post(`${FILEURL}/api/v${version}/File`, formData, header);
    return res;
  }
  public async addCompany(addJson) {
    let res = await this.reqService.post(`${PASSPORTURl}/api/v${version}/Company`, addJson);
    return res;
  }
  public async editCompany(editJson) {
    let res = await this.reqService.put(`${PASSPORTURl}/api/v${version}/Company`, editJson);
    return res;
  }
  public async getAllCompany(getJson) {
    let res = await this.reqService.get(`${PASSPORTURl}/api/v${version}/Company`, getJson);
    return res;
  }
  public async getCompanyById(id) {
    let res = await this.reqService.get(`${PASSPORTURl}/api/v${version}/Company/` + id, {});
    return res;
  }
  public async getInvitationExamine(json) {
    let res = await this.reqService.get(`${PASSPORTURl}/api/v${version}/Company/getinvitationcompany`, json);
    return res;
  }
  public async addRoleUser(addJson) {
    let res = await this.reqService.post(`${TREEURL}/api/v${version}/RoleUser/add`, addJson, this.getHeaderTenantId());
    return res;
  }
  public async addRoleMenu(addJson) {
    let res = await this.reqService.put(`${TREEURL}/api/v${version}/Role/role-menus`, addJson, this.getHeaderTenantId());
    return res;
  }
  public async delRoleUser(json) {
    let res = await this.reqService.delete(`${TREEURL}/api/v${version}/RoleUser`, json, this.getHeaderTenantId());
    return res;
  }
  public async delRole(json) {
    let res = await this.reqService.delete(`${TREEURL}/api/v${version}/Role`, json, this.getHeaderTenantId());
    return res;
  }
  public async addPro(addJson) {
    let res = await this.reqService.post(`${CLOUDURL}/api/v${version}/Project`, addJson);
    return res;
  }
  public async getAppointPro(json) {
    let res = await this.reqService.get(`${CLOUDURL}/api/v${version}/Project`, json);
    return res;
  }
  public async getProById(id) {
    let res = await this.reqService.getSSO(`${CLOUDURL}/api/v${version}/Project/` + id, {});
    return res;
  }
  public async editPro(editJson) {
    let res = await this.reqService.put(`${CLOUDURL}/api/v${version}/Project`, editJson);
    return res;
  }
  public async deletePro(id) {
    let res = await this.reqService.delete(`${CLOUDURL}/api/v${version}/Project/` + id, {});
    return res;
  }
  public async relation(json, projectId) {
    let Header = {
      TenantId: projectId
    };
    let res = await this.reqService.post(`${TREEURL}/api/v${version}/Attachment`, json, Header);
    return res;
  }
  public async getProgressModal(json) {
    let res = await this.reqService.get(`${FILEURL}/api/v${version}/File/convert-process`, json);
    return res;
  }
  public async getRoleMenu(json, TenantId?) {
    let res;
    if (TenantId) {
      let Header = { TenantId };
      res = await this.reqService.get(`${TREEURL}/api/v${version}/Role`, json, Header);
    } else {
      res = await this.reqService.get(`${TREEURL}/api/v${version}/Role`, json, this.getHeaderTenantId());
    }
    return res;
  }
  public async getAttachment(json) {
    let res = await this.reqService.get(`${TREEURL}/api/v${version}/Attachment`, json, this.getHeaderTenantId());
    return res;
  }
  public async getAttachmentById(id) {
    let res = await this.reqService.get(`${TREEURL}/api/v${version}/Attachment/` + id, {}, this.getHeaderTenantId());
    return res;
  }
  public async getCompanyTree(json) {
    let res = await this.reqService.get(`${CLOUDURL}/api/v${version}/CompanyStructure/tree`, json);
    return res;
  }
  public async getCompanyDropdownList(json) {
    let res = await this.reqService.get(`${CLOUDURL}/api/v${version}/CompanyStructure/DropdownList`, json);
    return res;
  }
  public async getCurrentUserInfo() {
    let res = await this.reqService.get(`${PASSPORTURl}/api/v${version}/User/currentUserInfo`, {});
    return res;
  }
  public async getUserInfo(id) {
    let res = await this.reqService.get(`${PASSPORTURl}/api/v${version}/User/` + id, {});
    return res;
  }
  public async addAudit(addJson) {
    let res = await this.reqService.post(`${PASSPORTURl}/api/v${version}/CompanyUser/Audit`, addJson);
    return res;
  }
  public async addDepart(addJson) {
    let res = await this.reqService.post(`${CLOUDURL}/api/v${version}/CompanyStructure`, addJson);
    return res;
  }
  public async addJob(addJson) {
    let res = await this.reqService.post(`${CLOUDURL}/api/v${version}/Job`, addJson);
    return res;
  }
  public async delDepart(json) {
    let res = await this.reqService.delete(`${CLOUDURL}/api/v${version}/CompanyStructure`, json);
    return res;
  }
  public async editDepart(editJson) {
    let res = await this.reqService.put(`${CLOUDURL}/api/v${version}/CompanyStructure/`, editJson);
    return res;
  }
  public async editlookDepart(id) {
    let res = await this.reqService.get(`${CLOUDURL}/api/v${version}/CompanyStructure/` + id, {});
    return res;
  }
  public async getJob(json) {
    let res = await this.reqService.get(`${CLOUDURL}/api/v${version}/Job`, json);
    return res;
  }
  public async getJobById(roleid) {
    let res = await this.reqService.get(`${CLOUDURL}/api/v${version}/Job/` + roleid, {});
    return res;
  }
  public async bindCompanyUser(addJson) {
    const res = await this.reqService.post(`${PASSPORTURl}/api/v${version}/CompanyUser/BindCompanyUser`, addJson);
    return res;
  }
  public async unBindCompanyUser(addJson) {
    let res = await this.reqService.post(`${PASSPORTURl}/api/v${version}/CompanyUser/UnBindCompanyUser`, addJson);
    return res;
  }
  public async delJobUser(json) {
    let res = await this.reqService.delete(`${CLOUDURL}/api/v${version}/JobUser`, json);
    return res;
  }
  public async changeJobUser(addJson) {
    let res = await this.reqService.put(`${CLOUDURL}/api/v${version}/JobUser/changejobuser`, addJson);
    return res;
  }
  public async editJobUser(addJson) {
    let res = await this.reqService.post(`${CLOUDURL}/api/v${version}/JobUser`, addJson);
    return res;
  }
  public async editJobInfo(addJson) {
    let res = await this.reqService.put(`${CLOUDURL}/api/v${version}/Job/job-info`, addJson);
    return res;
  }
  public async delJob(json) {

    let res = await this.reqService.delete(`${CLOUDURL}/api/v${version}/Job`, json);
    return res;
  }
  public async saveUser(addJson) {
    let res = await this.reqService.post(`${PASSPORTURl}/api/v${version}/User/profile`, addJson);
    return res;
  }
  public async setAdminById(userId) {
    let res = await this.reqService.post(`${PASSPORTURl}/api/v${version}/UserRole/setadmin/` + userId, {});
    return res;
  }
  public async getUserfullInfo(param) {
    let res = await this.reqService.get(`${PASSPORTURl}/api/v${version}/User/userfullinfo`, param);
    return res;
  }
  public async getTreeById(id: string) {
    let res = await this.reqService.get(`${FILEURL}/api/v${version}/BIMModel/modelTree/` + id, {}, this.getHeaderTenantId());
    return res;
  }
  public async getOldTreeById(id: string) {
    let res = await this.reqService.get(`${OLDTREEURL}/api/v${version}/BIMModel/modelTree/` + id, {}, this.getHeaderTenantId());
    return res;
  }
  ///////////////////////////////////// fileServer//////////////////////////////////
  /**
   * 删除链接模型
   * @param modelGroupId 
   * @param modelNames 
   */
  public async deleteRelationModels(param) {
    let res = await this.reqService.post(`${FILEURL}/api/v${version}/BIMModel/deleteModel`, param, this.getHeaderTenantId());
    return res;
  }
  /**
   * 获取轴网和标高3.0
   * @param modelGroupId 
   * @param modelId 
   */
  public async getGridsAndLevles(modelGroupId: string, modelId: string) {
    let res = await this.reqService.get(`${FILEURL}/api/v${version}/BIMModel/gridsAndLevles`, { modelGroupId, modelId }, this.getHeaderTenantId());
    return res;
  }
  /**
   * 获取轴网标高2.0
   * @param json 
   */
  public async getGridsAndLevlesOld(json) {
    let res = await this.reqService.get(OLDTREEURL + "/api/v1/BIMModel/gridsAndLevles", json, this.getHeaderTenantId());
    return res;
  }
  /**
   * 通过构件Id获取属性3.0
   * @param modelGroupId 
   * @param shapeInstanceId 
   */
  public async getPropertyById(modelGroupId: string, shapeInstanceId: string) {
    let res = await this.reqService.get(`${FILEURL}/api/v${version}/BIMModel/getbyid`, { modelGroupId, shapeInstanceId }, this.getHeaderTenantId());
    return res;
  }
  /**
   * 通过构件Id获取属性2.0
   * @param modelGroupId 
   * @param shapeInstanceId 
   */
  public async getPropertyByIdOld(modelGroupId: string, shapeInstanceId: string) {
    let res = await this.reqService.get(`${OLDTREEURL}/api/v${version}/BIMModel/getbyid`, { modelGroupId, shapeInstanceId }, this.getHeaderTenantId());
    return res;
  }
  /**
   * 获取版本信息
   * @param json 
   */
  public async getAppversion(json?) {
    let res = await this.reqService.get(`${PASSPORTURl}/api/v${version}/Appversion`, json);
    return res;
  }
  /**
   * 获取文件组
   * @param filter 
   */
  public async getFileGroup(filter?) {
    let res = await this.reqService.get(`${FILEURL}/api/v${version}/FileGroup`, filter, this.getHeaderTenantId());
    return res;
  }
  /**
   * 获取文件组信息
   * @param id 
   */
  public async getFileGroupById(id: string) {
    let res = await this.reqService.get(`${FILEURL}/api/v${version}/FileGroup/${id}`, {}, this.getHeaderTenantId());
    return res;
  }
  /**
   * 删除文件组
   * @param id 
   */
  public async deleteFileGroup(id: string) {
    let res = await this.reqService.delete(`${FILEURL}/api/v${version}/FileGroup`, { id }, this.getHeaderTenantId());
    return res;
  }
  /**
   * 获取文件列表
   * @param filter 
   */
  public async getFileList(filter?) {
    let res = await this.reqService.get(`${FILEURL}/api/v${version}/File`, filter, this.getHeaderTenantId());
    return res;
  }
  /**
   * 以formData形式上传文件
   * @param formData 
   */
  public async formDataFile(formData) {
    let res = await this.reqService.post(FILEURL + "/api/v1/File", formData);
    return res;
  }
  ///////////////////////////////////////// 健康监测-modelLink///////////////////////////////////
  /**
   * 创建工作集目录
   * @param form 
   */
  // public async postModelLinkMenu(form: ModelLinkViewModel) {
  //   let res = await this.reqService.post(TREEURL + "/api/v1/ModelLink", form, this.getHeaderTenantId());
  //   return res;
  // }
  /**
   * 删除工作集目录
   * @param form 
   */
  public async deleteModelLinkMenu(id: string) {
    let res = await this.reqService.delete(TREEURL + "/api/v1/ModelLink", { id }, this.getHeaderTenantId());
    return res;
  }
  /**
   * 修改工作集目录
   * @param form 
   */
  public async putModelLinkMenu(form) {
    let res = await this.reqService.put(TREEURL + "/api/v1/ModelLink", form, this.getHeaderTenantId());
    return res;
  }
  /**
   * 获取工作集目录列表
   */
  public async getModelLinkList(filter) {
    let res = await this.reqService.get(TREEURL + "/api/v1/ModelLink", filter);
    return res;
  }
  /**
   * 创建标记点
   * @param form 
   */
  public async postModelDevice(form) {
    let res = await this.reqService.post(TREEURL + "/api/v1/ModelDevice", form, this.getHeaderTenantId());
    return res;
  }

  /**
   * 创建标记点
   * @param form 
   */
  public async putModelDevice(form) {
    let res = await this.reqService.put(TREEURL + "/api/v1/ModelDevice", form, this.getHeaderTenantId());
    return res;
  }

  /**
   * 创建标记点
   * @param form 
   */
  public async deleteModelDevice(id) {
    let res = await this.reqService.delete(TREEURL + "/api/v1/ModelDevice", { id }, this.getHeaderTenantId());
    return res;
  }

  /**
   * 获取标记点
   * @param filter 
   */
  public async getModelDeviceList(filter) {
    let res = await this.reqService.get(TREEURL + "/api/v1/ModelDevice/monitors", filter, this.getHeaderTenantId());
    return res;
  }

  /**
   * 获取设备列表
   * @param filter 
   */
  public async getMonitorList(filter?) {
    let param = new Object();
    param["PageSize"] = 1000;
    param["PageNumber"] = 1;
    for (const key in filter) {
      if (filter.hasOwnProperty(key)) {
        param[key] = filter[key];
      }
    }
    let res = await this.reqService.get(MONITORURL + "/api/v1/Device/device-management", param, this.getHeaderTenantId());
    return res;
  }

  /**
   * 绑定设备
   */
  public async postDeviceMonitor(form) {
    let res = await this.reqService.post(TREEURL + "/api/v1/DeviceMonitor/bind-monitors", form, this.getHeaderTenantId());
    return res;
  }

  /**
   * 解绑设备
   */
  public async deleteDeviceMonitor(idArray: String[]) {
    let res = await this.reqService.post(TREEURL + "/api/v1/DeviceMonitor/remove-monitors", idArray, this.getHeaderTenantId());
    return res;
  }

  /**
   * 获取设备列表
   */
  public async postMonitorDetail(form) {
    let res = await this.reqService.post(MONITORURL + "/api/v1/Device/device-management/getdevicestatus", form, this.getHeaderTenantId());
    return res;
  }

  public async getSettlementList(equipmentType: string, deviceCode: string) {
    let param = new Object();
    param["PageSize"] = 1000;
    param["PageNumber"] = 1;
    param["deviceCode"] = deviceCode;
    switch (equipmentType) {
      case '01':
        return await this.reqService.get(`${MONITORURL}/api/v${version}/Settlement/Settlement-management`, param);
      case '02':
        return await this.reqService.get(`${MONITORURL}/api/v${version}/LaserRanging/LaserRanging-management`, param);
      case '03':
        return await this.reqService.get(`${MONITORURL}/api/v${version}/Meteorological/Meteorological-management` ,param);
      case '04':
        return await this.reqService.get(`${MONITORURL}/api/v${version}/StressStrain/StressStrain-management`, param);
      case '05':
        return await this.reqService.get(`${MONITORURL}/api/v${version}/Fracturemeter/Fracturemeter-management`, param);
      case '06':
        return await this.reqService.get(`${MONITORURL}/api/v${version}/Inclinometer/Inclinometer-management`, param);
    }
  }
}
